-
Notifications
You must be signed in to change notification settings - Fork 924
Support indefinite length BER encodings in PKCS #7 #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
53e6812 to
5158da6
Compare
wolfcrypt/src/asn.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a public function we should have a length input for Der size as well so we don't overwrite the Der buffer. It will also catch programming errors on our side.
wolfcrypt/src/pkcs7.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check the return code here, there's no guarantee in the future that if the first call succeeds on the length check that the second call will succeed as well. Also a good static analyzer should warn on this.
wolfcrypt/src/pkcs7.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return code check needed.
|
Looks good, please resolve conflict. |
dgarske
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a BER indefinite length encoded message we can add a test with? It would be ideal to have a wolfCrypt test for wc_BerToDer or for the PKCS7 calls.
wolfcrypt/src/pkcs7.c
Outdated
| ret = wc_BerToDer(pkiMsg, pkiMsgSz, NULL, &len); | ||
| if (ret != LENGTH_ONLY_E) | ||
| return ret; | ||
| pkcs7->der = XMALLOC(len, pkcs7->heap, DYNAMIC_TYPE_PKCS7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We find results from XMALLOC need to have a cast in front due to some compilers. (byte*)XMALLOC().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
wolfcrypt/test/test.c
Outdated
| pkcs7.unprotectedAttribs = testVectors[i].attribs; | ||
| pkcs7.unprotectedAttribsSz = testVectors[i].attribsSz; | ||
| pkcs7.heap = HEAP_HINT; | ||
| #ifdef ASN_BER_TO_DER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend doing an wc_PKCS7_Init above and remove this. Our test examples should do the init, so the PKCS7 struct is memset to 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
@dgarske sent an example case by email just in case we still need one. |
dgarske
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look great! I'm marking this approved. Up to you if you want to add a BER to DER test in this PR or if you want to add later.
toddouska
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
Also support explicit octet string in enveloped data.